local xiangle = fk.CreateSkill {
  name = "lingling__xiangle",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__xiangle"] = "享乐",
  [":lingling__xiangle"] = "锁定技，回合结束时，若你已受伤，你回复1点体力并摸一张牌；若你手牌最少，则额外摸一张牌；"..
  "若你未受伤或因此回复至满，你失去此技能。",

  ["#lingling__huhai_EasterEgg"] = "我做梦都想当皇帝！我太想了！",
}

xiangle:addEffect(fk.TurnEnd, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xiangle.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(xiangle.name)
    local min = table.every(room.alive_players, function (p)
      return p:getHandcardNum() >= player:getHandcardNum()
    end)
    if not player:isWounded() then
      room:notifySkillInvoked(player, xiangle.name, "negative")
      room:handleAddLoseSkills(player, "-lingling__xiangle")
    else
      room:notifySkillInvoked(player, xiangle.name, "support")
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = xiangle.name,
      }
      if player.dead then return end
      if not player:isWounded() then
        room:handleAddLoseSkills(player, "-lingling__xiangle")
      end
      player:drawCards(min and 2 or 1, xiangle.name)
    end
  end,
})

xiangle:addEffect(fk.Deathed,{
  can_refresh = function (self, event, target, player, data)
    return player.general == "lingling__huhai" and player:getMark("lingling__xiangle_EasterEgg") == 0 and table.find(player.room.alive_players,function (cp)
      return cp.general == "lingling__zhaogao" or cp.general == "lingling__lisi"
    end)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:sendLog{
      type = "#lingling__huhai_EasterEgg",
      from = player.id,
      toast = true,
    }
    room:changeMaxHp(player, 1)
  end,
})

return xiangle
